<template>
    <div id='agreement'>
        <agreement
            :no='borrowNo'
            :iou='iouNo'
            :type='type'
            :show='showAgreement'></agreement>
    </div>
</template>

<script>
    import { Promise } from 'es6-promise'
    import agreement from '../components/Agreement.vue'
    import { getOS } from '../utils/utils'
    import  { mapGetters, mapActions }  from 'vuex'


    export default {
        components:{
            agreement
        },
        methods:{
            // actions
            ...mapActions([
                'showLoading',
                'hideLoading',
                'setMsgTip',
                'setMsgTipStyle',
                'setSessionId',
                'localInfo'
            ]),
            currentRouter(item){
                let routerArr = this.$route.matched
                let matchRouter = _.some(routerArr,['name',item.router])
                return matchRouter
            },
            goRouter(item,isSub){
                let thisRouter
                let routers = item.subRouters

                if(isSub === 'sub'){
                    if(this.$route.name == item) return
                    this.$router.push(item)
                    return
                }

                if(routers.length > 1){
                    item.opened = !item.opened
                    return
                }

                thisRouter = routers[0]
                if(this.$route.name == thisRouter.name) return
                this.$router.push(thisRouter)
            },
            goLogin(){
                // this.setSessionId('')
                this.$router.push({
                    name:'login'
                })
            }
        },
        data() {
            return {
                showAgreement:true,
                type:this.$route.query.type,
                borrowNo:this.$route.query.borrowNo,
                iouNo:this.$route.query.iouNo,
            }
        },
        computed:{
            ...mapGetters([
                'loading',
                'msgTip',
                'localInfo',
            ]),
            admin(){
                return this.localInfo.admin
            },
            sessionId(){
                return this.localInfo.sessionId
            },
            needLogin(){
                return this.localInfo.needLogin
            },
            routerAnimation(){
                return this.localInfo.routerAnimation
            },
            routerAnim(){
                if(this.os == 'Android'){
                    return ''
                }
                if(this.os != 'Android'){
                    return this.routerAnimation
                }
            },
            routerMode(){
                if(this.os == 'Android'){
                    return 'out-in'
                }
                if(this.os != 'Android'){
                    return ''
                }
            }
        },
        created(){
            // this.setMsgTipStyle({ top:'100px' })
        },
        watch: {
            'needLogin'(newVal,oldVal){
                if(newVal == oldVal) return
                if(newVal === true)
                this.$router.replace({
                    name:'login'
                })
            }
        }
    }
</script>

<style lang="scss">
    @import "../sass/variables";
    @import "../sass/extends";
    @import "../sass/mixins";

    #agreement{
        .component-modal__container{
            top:0;
            height:100%;
            max-height:100%;
        }
        .component-modal__close{
            display: none;
        }
    }
</style>
